package com;

import java.net.ServerSocket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class MySocketServer {
	static ExecutorService epool = Executors.newFixedThreadPool(100);
	static volatile AtomicInteger socketNum = new AtomicInteger(0);
	static MyStack<ThreadSocketServer> mystack = new MyStack<ThreadSocketServer>();//相当于tomcat中的HttpConnector 线程池
	ServerSocket serverSocket;
	int maxSocketCount = 10;
	public void mainServerStart() throws Exception {
		serverSocket = new ServerSocket(1212);
		try{
			int a=0;
			while(a<maxSocketCount){
				ThreadSocketServer threadSocket = mystack.pop(); 
				if(threadSocket==null){//tomcat中的HttpProcessor  
					threadSocket = new ThreadSocketServer(this);
				}
				epool.execute(threadSocket);
				a++;
			}
			
		}catch(Exception e){
			
		}
	}
	
	public void recycle(ThreadSocketServer threadSocket){
		System.out.println("MySocketServer recycle");
		mystack.push(threadSocket);
	}
	public ServerSocket getServerSocket(){
		return this.serverSocket;
	}

	public static void main(String[] args) {
		
	}
}
